import React, {Component} from "react";
import {
    Button,
    Form,
    Switch,
    Radio,
    DatePicker,
    Icon,
    InputNumber,
    Input,
    Select,
    Checkbox,
    Row,
    Col,
    message
} from "antd";
import auth from "../../common/auth";
const createForm = Form.create;
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const CheckboxGroup = Checkbox.Group;
const Option = Select.Option;
function noop() {
    return false;
}
class FuncForm extends Component {
    state = {
        option: '',
        loading: false,
        visible: true
    }


    handleChange(value) {
    }

    componentDidUpdate(nextProps, nextState) {
    }

    componentDidMount() {
    }

    render() {
        const {getFieldDecorator} = this.props.form;
        const formItemLayout = {
            labelCol: {span: 6},
            wrapperCol: {span: 18}
        };
        const option = this.props.init.option;
        let isDisabled = option == "view" ? true : false;
        let {recorddata,formfuncData} =this.props.init;
        if(!formfuncData){
            formfuncData=[];
        }
        return (
            <div >
                <Form horizontal>
                    <FormItem
                        label="菜单名称："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}
                        hasFeedback>
                        {getFieldDecorator('funcname', {
                            initialValue: recorddata.funcname,
                            rules: [
                                {required: true, message: '请输入菜单名称'}
                            ],
                        })(<Input placeholder="请输入菜单名称" disabled={(isDisabled )} />)}

                    </FormItem>
                    <FormItem
                        label="上级菜单："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}
                        hasFeedback>
                        {getFieldDecorator('parentid', {
                            initialValue: recorddata.parentid ? recorddata.parentid.toString() : "0",
                            rules: [
                                {required: true, message: '请选择上级菜单'}
                            ],
                        })(<Select style={{width: '100%'}} onChange={this.handleChange.bind(this)} defaultActiveFirstOption
                                >
                            <Option key={0}>一级菜单</Option>
                            {formfuncData.map(items => <Option key={items.id}>{items.funcname}</Option>)}
                        </Select>)}

                    </FormItem>
                    <FormItem
                        label="是否用于菜单："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}>
                        {getFieldDecorator('ismenu', {initialValue:recorddata.ismenu ? recorddata.ismenu : '1'})
                        (<RadioGroup disabled={isDisabled}>
                            <Radio value="1">是</Radio>
                            <Radio value="2">否</Radio>
                        </RadioGroup>)}

                    </FormItem>
                    <FormItem
                        label="图标："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}>
                        {getFieldDecorator('icon', {initialValue: recorddata.icon})(
                          <Input placeholder="请输入选择图标" disabled={isDisabled}/>
                        )}
                    </FormItem>
                    <FormItem
                        label="URL："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}
                        hasFeedback>
                        {getFieldDecorator('url', {
                            initialValue: recorddata.url,
                            rules: [
                                {required: true, message: '请输入菜单地址'}
                            ],
                        })(
                          <Input placeholder="请输入菜单地址" disabled={isDisabled}/>
                        )}

                    </FormItem>
                    <FormItem
                        label="顺序号："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}
                        hasFeedback>
                        {getFieldDecorator('seq', {initialValue: recorddata.seq ? recorddata.seq : 0})(
                          <InputNumber style={{width: 180}}  placeholder="请输入顺序号" disabled={isDisabled} />
                        )}

                    </FormItem>
                    <FormItem
                        label="描述："
                        labelCol={{span: 7}}
                        wrapperCol={{span: 12}}>
                        {getFieldDecorator('described', {initialValue: recorddata.described})(
                          <Input type="textarea" placeholder="请输入描述信息" id="textarea" disabled={isDisabled} />
                        )}

                    </FormItem>
                    {getFieldDecorator('id', {initialValue: recorddata.id})(<Input type="hidden"  />)}

                </Form>
            </div>

        );
    }
}
;

FuncForm = createForm()(FuncForm);
export default FuncForm
